package cn.kgc.springcloud.service.impl;

import cn.kgc.springcloud.client.ClazzClient;
import cn.kgc.springcloud.entity.Clazz;
import cn.kgc.springcloud.vo.GroupVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.kgc.springcloud.entity.Group;
import cn.kgc.springcloud.service.GroupService;
import cn.kgc.springcloud.mapper.GroupMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;


@Service
public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group> implements GroupService{

    @Autowired
    private GroupMapper groupMapper;

    @Autowired
    private ClazzClient clazzClient;

    @Override
    public List<GroupVO> getGroupVOList() {

        List<Group> groups = groupMapper.selectList(null);
        List<GroupVO> collect = groups.stream().map(group -> {
            GroupVO groupVO = new GroupVO();
            BeanUtils.copyProperties(group,groupVO);
            //根据小组所属班级的id  查询班级详细信息 进行封装
            Integer clazzid = Integer.valueOf(group.getClazzid());
            Clazz clazz = clazzClient.getById(clazzid);
            groupVO.setClazz(clazz);
            return groupVO;
        }).collect(Collectors.toList());
        return collect ;
    }
}




